package com.alvin.demo.controller;

import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class IndexController {

    @GetMapping("/")
    public String indexPage() {
        Object principal = SecurityUtils.getSubject().getPrincipal();
        if (principal == null){
            return "login";
        }
        return "redirect:/index.html";
    }

    @GetMapping("index.html")
    public String mainPage(){
        return "main";
    }

    @GetMapping("/logout")
    public String logout() {
        SecurityUtils.getSubject().logout();
        return "redirect:/";
    }

    @GetMapping("/error/404.html")
    public String error404() {
        return "errorPage/404";
    }

    @GetMapping("/error/403.html")
    public String error403() {
        return "errorPage/403";
    }

}
